package DBTasks;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Stephen
 *
 */

public class ShelterSearch extends DBTask {
	
	private static String queryString = "SELECT * From Shelter WHERE Zip_Code = ?";
	
	
	public static List<Shelter> search(String zipcode){
		return search(Integer.parseInt(zipcode));
	}
	
	public static List<Shelter> search(int zipcode){
		
		List<Shelter> shelters = new ArrayList<Shelter>();
		Shelter shelter;
		
		ResultSet rs;
		try {
			PreparedStatement query = con.prepareStatement(queryString);
			query.setInt(1, zipcode);
			rs = query.executeQuery();
			while (rs.next()){
				shelter = new Shelter();
				shelter.setName(rs.getString("Name"));
				shelter.setPhoneNumber(rs.getString("Phone"));
				shelter.setDaysOpen(rs.getString("Days_Open"));
				shelter.setHoursOpen(rs.getString("Hours_Open"));
				shelter.setAddress(rs.getString("Street_City_State")+ " " + rs.getInt("Zip_Code"));
				shelters.add(shelter);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return shelters;
	}
	

}
